function R = lpcvd_2DSurface_plotCov(h,x,y)
% lpcvd_2DSurface_autocorrlength(h,x,y,MODE)
% INPUT:
% h:
% x:
% y:
% MODE:
% The following definition of multi-dimensional autocorrelation is from
% Wiki: http://en.wikipedia.org/wiki/Auto-correlation
%
% R(m,n) = \sum_{i,j}x_{i,j}x_{i+m,j+n}
%

assert(size(h,1)==length(x),'Dimension mismatch');
assert(size(h,2)==length(y),'Dimension mismatch');
R = zeros(size(h));
nx = length(x);
ny = length(y);
for m = 0:(nx-1)
    for n = 0:(ny-1)
        mi = m+1;
        ni = n+1;
%         for i = 1:(length(x)-m)
%             for j = 1:(length(y)-n)
        for i = 1:(nx)
            for j = 1:(ny)               
                R(mi,ni) = R(mi,ni)+h(i,j)*h(mod(i+m-1,nx)+1,mod(j+n-1,ny)+1);
            end
        end
    end
end